package com.lizhao.controller.user;

import com.lizhao.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")

//注解作用：描述类
@Api(tags = "用户控制器")
public class UserController {
    @GetMapping("/getUsers")

    //注解作用：描述方法
    @ApiOperation(value = "查询所有用户", notes = "查询所有用户信息")
    public List<User> getAllUsers(){
        User user1 = new User();
        user1.setId(1);
        user1.setName("lizhao");
        user1.setAge(999);
        user1.setAddress("天上人间");

        User user2 = new User();
        user2.setId(2);
        user2.setName("黑色暴风飞车侠");
        user2.setAge(999);
        user2.setAddress("落袋为安");

        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        return list;
    }

    //注解作用：描述方法
    @PostMapping("/save")
    @ApiOperation(value = "新增用户", notes = "新增用户信息")
    public String save(@RequestBody User user){
        return "用户信息添加成功！";
    }

    //注解作用：描述方法
    @PostMapping("/update")
    @ApiOperation(value = "修改用户", notes = "修改用户信息")
    public String update(@RequestBody User user){
        return "用户信息修改成功！";
    }

    //注解作用：描述方法
    @PostMapping("/delete")
    @ApiOperation(value = "删除用户", notes = "删除用户信息")
    public String delete(int id){
        return "用户信息删除成功！";
    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, type = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, type = "Integer")
    })
    public String findByPage(@PathVariable String pageNum, @PathVariable String pageSize){
        return "OK";
    }
}